// pages/user/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.height + 'px',
    navigationBarHeight: (app.globalData.height + 44) + 'px',
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    typeList:[
      {name:'简餐便当',img:'../../../static/images/jcbd.png',type:6},
      {name:'水果生鲜',img:'../../../static/images/sgsx.png',type:7},
      {name:'炸鸡烧烤',img:'../../../static/images/zjsk.png',type:8},
      {name:'粉面粥点',img:'../../../static/images/fmzd.png',type:9},
      {name:'丰富宵夜',img:'../../../static/images/ffxy.png',type:10},
      {name:'汉堡披萨',img:'../../../static/images/hbps.png',type:11},
      {name:'香锅冒菜',img:'../../../static/images/xgmc.png',type:12},
      {name:'奶茶糕点',img:'../../../static/images/ncgd.png',type:13},
      {name:'馄饨水饺',img:'../../../static/images/hdsj.png',type:14},
      {name:'轻食西餐',img:'../../../static/images/qsxc.png',type:15}
    ],
    shopList: [],//店铺列表
    pageSize:5,//分页每页显示条数
    pageNum:1,//当前页数
    total:20,//总条数
    search:null,//搜索内容
    tabList: [
      {name:'全部',id:1},
      {name:'汉堡薯条',id:2},
      {name:'意面披萨',id:3},
      {name:'轻食沙拉',id:4}
    ],
    tabIndex:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({ title: options.name }) 
    this.getList()
  },
  changeTab(event){
    //切换tab
    var dataset=event.currentTarget.dataset
    this.setData({
      tabIndex:dataset.id
    })
  },
  cancle(){
    this.setData({
      search:null
    })
  },
  setInputSearch(e){
    //监听搜索框输入
    this.setData({
      search:e.detail.value
    })
  },
  bindconfirm(e){
    //点击键盘--搜索
    var that=this;
    var discountName=e.detail.value['search - input'] ?e.detail.value['search - input'] : e.detail.value 
    console.log('e.detail.value', discountName)
    this.setData({
      search:discountName
    })

    //刷新动画
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)
  },
  getList(){
    let arr=[
      {name:'烤肉',score:'4.7',num:'478',send:'15',sendMoney:'0.9',time:'42',juli:'1.8'},
      {name:'烤肉',score:'4.7',num:'478',send:'15',sendMoney:'0.9',time:'42',juli:'1.8'},
      {name:'烤肉',score:'4.7',num:'478',send:'15',sendMoney:'0.9',time:'42',juli:'1.8'},
      {name:'烤肉',score:'4.7',num:'478',send:'15',sendMoney:'0.9',time:'42',juli:'1.8'},
      {name:'烤肉',score:'4.7',num:'478',send:'15',sendMoney:'0.9',time:'42',juli:'1.8'}
    ]
    let data=this.data.shopList.concat(arr)
    this.setData({
      shopList:data,
      pageNum:this.data.pageNum++
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('下拉了')
    setTimeout(()=>{
      wx.stopPullDownRefresh()
    },1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.total>this.data.shopList.length){
      setTimeout(()=>{
        this.getList()
      },1000)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})